$(function() {
	router = new Router({
		container: "#container",
		enterTimeout: 250,
		leaveTimeout: 250
	});
	var home = {
		url: "/",
		className: "home",
		render: function() {
			return setTitle("宝店客"), template("tpl_home", {nav:1})
		},
		bind: function() {
			var _this=this;
			/*var swiper=new Swiper("#home_swiper", {
				autoHeight: true
			});*/
			//分页查询所有宝店客收入信息
			pullLoadData(this,'#baodianke_data','#baodianke_data .stores',"firework/invite-bonus.json","tpl_home_data",{},function(data){
				if(data.code==404 && data.count<1){
					$(_this).find("#baodianke_data").hide();
				}
			});
		}
	};
	var privilege = {
		url: "/privilege",
		className: "privilege",
		render: function() {
			return setTitle("钻石"), template("tpl_privilege", {nav:2})
		},
		bind: function() {
			var _this=this;
			ajaxGet("firework/bdk/counts.json",{type:1},function(data){
				$(_this).find("#number").html(data.data);
			});
		}
	};
	router.push(privilege);
	var goReplace="";
	var activeStatus=0;
	var active = {
		url: "/active",
		className: "active",
		render: function() {
			var _this=this;
			$(window).unbind("scroll");
			$(window).on('scroll', function(ev){				
				if ($(document).scrollTop() >= 20) {					
					$('.pull').hide();
				}
			});			
			//判断用户的状态
			return new Promise(function (resolve, reject){
				setTitle("幸运");
				ajaxGet("firework/bdk/myluckyinfo.json",{},function(data){
					var data=data.data;
					data["nav"]=3;
					if(data.appstatus == 0){
						activeStatus=2;
						//审核中
						resolve(template("tpl_active_wait", data));
					}else if(data.appstatus == 1){
						//审核成功
						if(data.bdk_schedule_id>0){
							//已选择地区，显示审核进度
							_this.className="allowanced";
							goReplace="#/allowancedlucky/"+data.bdk_schedule_id;
							resolve(template("tpl_allowanced", data));///allowanced
							//window.location.replace("#/allowanced/"+data.bdk_schedule_id);
						}else{
							//未选择地区
							_this.className="actived";
							//获取已选择的城市
							data["city"]=getCookieJson("city");
							data["county"]=getCookieJson("county");
							resolve(template("tpl_select_city", data));
						}
					}else if(data.appstatus == 2){
						//考核成功，可以选择其他
						resolve(template("tpl_active", {nav:3}));
					}else{
						activeStatus=3;
						//者审核失败				
						resolve(template("tpl_active_refuse", data));
					}
				},function(){
					activeStatus=1;
					//不存在申请
					resolve(template("tpl_active", {nav:3}));
				});
	        });
		},
		bind: function() {
			var _this=this;
			$('#inputNumber').focus(function(){
				$('.pull').hide();
			});
			if(goReplace!=""){
				window.location.replace(goReplace);
				goReplace="";
				return;
			}
			//公共的顶部
			initHeadFun(this);
			//独有的属性
			if(activeStatus==1){
				
			}else if(activeStatus==2){
				//正在审核
				$(_this).find("#btn_cancel").click(function(){
					var id=$(this).data("id");
					ajaxPost('firework/bdk/applydelete.json',{id:id},function(data){
						showInfoMsg("撤销成功");
						setTimeout(function(){
							window.location.replace("/firework/bdk/lucky.html")
						},1500);
					},function(data){
						showErrorMsg(data.message || "系统错误！");
					});
				});
			}else if(activeStatus==3){
				//拒绝
				//$(_this).find("#prop").html(template("tpl_allowanced_prop",data.data)).append("<div class='minfo'>"+data.data.moreinfo+"</div>");
			}
			
			//删除被拒绝的申请
			$(_this).find("#btn_rechage").click(function(){
				var id=$(this).data("id");
				ajaxPost('firework/bdk/applydelete.json',{id:id},function(data){
					window.location.reload();
				},function(data){
					showErrorMsg(data.message || "系统错误！");
				});
			});
			var cat_id=0,catname="";
			//提交审核
			$(_this).find("#btn_submit").click(function(){
				var county=getCookieJson("county");
				var countyid=0;
				if(county){
					countyid=county.id;
				}else{
					showErrorMsg("请选择地区");
					return false;
				}
				if(cat_id<1){
					showErrorMsg("请选择行业");
					return false;
				}
				ajaxPost('firework/schedule/signup.json', {id:countyid,cid:cat_id,catname:catname}, function (data) {
					//showInfoMsg('报名成功');
					$(_this).find("#success").show().find(".catname").html(catname);
					//window.location.replace("#/allowanced");
				},function(data){
					showErrorMsg(data.message || '报名失败');
				})
			});
			//选择考核的分类
			$(_this).find("#cate_ids").on("click",".weui-cell",function(){
				if(!$(this).hasClass("disabled")){
					cat_id=$(this).data("id");
					catname=$(this).data("name");
					$(this).addClass("cu").siblings().removeClass("cu");
				}else{
					//已经被别人选择了
					showErrorMsg("已被抢占，不允许选择！")
				}
			})
			//知道了，重新刷新页面，进入审核界面
			$(_this).find("#btn_close").click(function(){
				window.location.reload();
			});
			//自动加载行业数据
			if($(_this).find("#cate_ids").length>0){
				var county=getCookieJson("county");
				ajaxGet('firework/bdk/storeCategory.json',{id:county?county.id:0},function(data){
					$(_this).find("#cate_ids").html(template('tpl_select_city_cat',data))
				});
			}
		}
	};
	router.push(active);
	var diam_uid;
	var diamondinfo = {
		url: "/diamondinfo/:id",
		className: "diamondinfo",
		render: function() {
			diam_uid=this.params.id;
			return new Promise(function (resolve, reject){
				setTitle("钻石宝店客信息");
				ajaxGet("firework/bdk/info.json",{id:diam_uid},function(data){
					resolve(template("tpl_diamondinfo", data.data));
				},function(){
					//用户不存在
					diam_uid=0;
					resolve("<div class='empty'>用户不存在</div>");
				});
	        });
		},
		bind: function() {
			var _this=this;
			if(diam_uid>0){
				//特殊配置
				ajaxGet("firework/bdk/rules.json",{id:diam_uid},function(data){
					$(_this).find("#rules").html(template("tpl_diamond_rule",data.data))
				},function(){
					//默认配置
					$(_this).find("#rules").html(template("tpl_diamond_rule",{}))
				});
				//申请成为幸运宝店客
				$(_this).find("#btn_submit").click(function(){
					ajaxPost('firework/bdk/apply.json',{id:diam_uid},function(data){
						$(_this).find("#success").show();
					},function(data){
						showErrorMsg(data.message || "申请失败");
					});
				});
				//关闭返回上一页
				$(_this).find("#btn_close").click(function(){
					goback(-1)
				});
			}
		}
	};
	router.push(diamondinfo);
	var bdk_schedule_id=0;
	//幸运宝店客考核结果
	var active_result={
		url: "/active_result/:id",
		className: "active",
		render: function () {
			bdk_schedule_id=this.params.id;
			return new Promise(function (resolve, reject){
				setTitle("考核结果");
				ajaxGet("firework/schedule/scheduleProcess.json",{id:bdk_schedule_id},function(data){
					var infos=data.data;
					infos["nav"]=3;
					resolve(template("tpl_active_result", infos));
				},function(){
					resolve("");
				});
	        });
		},
		bind: function () {
			var _this=this;
			//直接跳转active输入邀请码页面
			$(_this).find("#btn_rechage").click(function(){
				window.location.replace("#/active")
			});
			initHeadFun(this);
		}};
	router.push(active_result);
	
	var income = {
		url: "/income",
		className: "income",
		render: function() {
			return setTitle("收益"), template("tpl_income", {nav:4})
		},
		bind: function() {
			var  _this=this;
			pullLoadData(this,'.weui-tab__panel','.weui-tab__panel .weui-panel__bd',"firework/meals/myorders.json","tpl_purchased_data",{status:1},function(data){
				if(data.code==404 && data.count<1){
					$(_this).find(".empty_data").show();
				}
			});
			//查询自己的信息
			/*ajaxGet("users/info/mime.json",{},function(data){
				var info= data.data;
				$(_this).find("#avatar").append($('<img>').attr("src",info.avatar))
				$(_this).find("#userinfo").append("<div>"+info.id+" "+info.nickname+"</div>")
			});*/
			//查询收益
			ajaxGet("firework/bdk/income.json",{},function(data){
				var da = data.data;
				da["nav"]=4;
				$(_this).find("#money").html(template("tpl_income_money", da));
			});
		}
	};
	router.push(income);
	//
	var preintroduce = {
		url: "/preintroduce",
		className: "preintroduce",
		render: function() {
			return setTitle("宝店客"), template("tpl_preintroduce", {});
		},
		bind: function() {
			var _this=this;
			
		}
	};
	router.push(preintroduce);
	//
	var introduce_list = {
		url: "/introduce_list",
		className: "introduce_list",
		render: function() {
			return setTitle("宝店客"), template("tpl_introduce_list", {});
		},
		bind: function() {
			var _this=this;
			var index = 2;																	
			var swiper = new Swiper('.swiper-container', {
				initialSlide: 0,//初始位置，如为2则初始为第三个图片
				preventLinksPropagation: true,//阻止click冒泡。拖动Swiper时阻止click事件。				
				loop: true,//true可循环
				autoplay: {
					delay: 1500,//多少毫秒切换一次
				},
				pagination:{
					el: '.swiper-pagination', //分页器容器的css选择器
					clickable: true, //点击分页器的指示点分页器会控制Swiper切换
				},
				effect : 'coverflow',
				slidesPerView: 2,
				centeredSlides: true,
				coverflowEffect: {
					rotate: 30,
					stretch: 10,
					depth: 60,
					modifier: 2,
					slideShadows : true
				},
			});					
			//滑动处理 		    
			var startX, startY;    
			document.addEventListener('touchstart', function (ev) {      
				startX = ev.touches[0].pageX;      
				startY = ev.touches[0].pageY;    
			}, false);    
			document.addEventListener('touchend', function (ev) {      
				var endX, endY;      
				endX = ev.changedTouches[0].pageX;      
				endY = ev.changedTouches[0].pageY;      
				var direction = GetSlideDirection(startX, startY, endX, endY);
				var t1;
				if (index === 2) {
					t1 = 0;
				} else {
					t1 = $('.list'+index).offset().top;    
				}				
				switch (direction) {        
					case 0:
						console.log('无操作');          
						break;        
					case 1:
						// 向上 
						index++;
						if (index >= 9) {
							index = 9;
						}        
						break;        
					case 2:
			            // 向下 						
						index--;
						if (index <= 2) {
							index = 2;
						}
						break;          
					default:
						      
				} 	
				$('body,html').animate({
					scrollTop: t1
				}, 300);													  				 				
			}, false);	
			function GetSlideDirection(startX, startY, endX, endY) {
				var dy = startY - endY;				
				var result = 0;	
				var limit = 10;	//------滑动力度--------		
				if (dy > limit) { //向上滑动 
					result = 1;
				} else if (dy < -limit) { //向下滑动 
					result = 2;
				} else {
					result = 0;
				}
				return result;
			}			
		}
	};
	router.push(introduce_list);
	//
	var introduce_detail = {
		url: "/introduce_detail",
		className: "introduce_detail",
		render: function() {
			return setTitle("宝店客"), template("tpl_introduce_detail", {nav: 1});
		},
		bind: function() {
			var _this=this;
			var page = 1;
			var pageSize = 4;			
			var arr_1 = [];
			var page2 = 1;
			var pageSize2 = 4;
			var arr_2 = [];
			var page3 = 1;
			var pageSize3 = 4;
			var obj3 = {
				page: page3,
				limit: pageSize3,
				reward: 1
			};
			var cityId = 0;
			var arr_3 = [];
			ajaxGet('utils/ip/city.json', {}, function(data3){				
				if (data3.code === 200) {
					cityId = data3.data.city_id;						
					storeData();									
				}
			});
			function storeData() {
				ajaxGet('mall/stores/findbycidsqid/'+ cityId +'.json', obj3, function(data){						
					if (data.code === 200) {
						arr_3 = data.data;
						if (arr_3.length < pageSize3) {
							$('.more3').html('无更多数据');
							$('.more3').off();
						}							
						$(_this).find('.vip_lists').append(template('tpl_store_data', data));
					}
				});
			}				
			$('.more3').on('click', function(){								
				go('#/vip_store');				
			});	
			//签约宝店收入即宝友
			ajaxGet('service/vips/income.json', {}, function(data){
				if (data.code === 200) {
					$(_this).find('.prices3').html(data.data.money);
				}				
			}, function(err){
				$(_this).find('.prices3').html(0);
			});
			//关联宝店获得的收益
			ajaxGet('firework/invite-bonus/income.json', {}, function(data){
				if (data.code === 200) {
					$(_this).find('.prices2').html(data.data.money);
				}				
			}, function(err){
				$(_this).find('.prices2').html(0);
			});
			//推荐会员特价
			function getData() {
				ajaxGet('firework/goods/findbyvip.json', {page: page,limit: pageSize}, function(data) {
					if (data.code === 200) {						
						arr_1 = data.data;						
						if (arr_1.length < pageSize) {
							$('.more1').html('无更多数据');
							$('.more1').off();
						}													
						$(_this).find('.goods_lists').append(template('tpl_goods_data', data));												
					}					
				});
			}	
			getData();	
			$('.more1').on('click', function(){				
				page++;
				getData();				
			});				
			//自己关联的宝店
			function invite() {
				ajaxGet('firework/invite-bonus.json', {page: page2,limit: pageSize2,mine: 1}, function(data){					
					if (data.code === 200) {
						arr_2 = data.data;						
						if (arr_2.length < pageSize2) {
							$('.more2').html('无更多数据');
							$('.more2').off();
						}
						$(_this).find('.lists').append(template('tpl_invite_data', data));
					}
				}, function(err){
					$('.more2').html('暂无数据');
					$('.more2').off();
				});
			}		
			invite();
			$('.more2').on('click', function(){				
				page2++;
				invite();
				if (arr_2.length < pageSize2) {
					$('.more2').html('无更多数据');
					$(this).off();
				}
			});		
			//关联宝店收益
			$('.income2').click(function(){
				go('treasure.html#/store_profit');
			});			
		}
	};
	router.push(introduce_detail);

	var make_money = {
		url: "/make_money",
		className: "make_money",
		render: function() {
			return setTitle("赚得更多"), template("tpl_make_money", {});
		},
		bind: function() {
			var _this=this;	
			var lat = '';
			var lon = '';			
			getDegree();
			function getDegree() { //获取经纬度
				Promise.all([getLocation(true), setJSAPI()]).then(function (value) {
					var v1 = value[0];	
					lat = v1.latitude;
					lon = v1.longitude;	
					$('.connect2').on('click', function(ev){	
						ev.stopPropagation();																			
						go('/wechat/pages/dianshang.html?longitude='+ lat +'&latitude='+ lon );
					});		
				});
			}	
			//多加一层才行	
			pullLoadData(this, '.lists', '.list2', 'firework/invite-bonus.json', 'tpl_invite_data', {mine: 1}, function(data){
												
			}, 'tpl_no_invite');
			
		}
	};
	router.push(make_money);

	var save_money = {
		url: "/save_money",
		className: "save_money",
		render: function() {
			return setTitle("省得更多"), template("tpl_save_money", {});
		},
		bind: function() {
			var _this=this;
			var index = 0;			
			var page = 1;
			var pageSize = 10;
			var classArr = [];	
			var dataArr = [];		
			var str = '';		
			var obj = {
				id: index,
				page: page,
				limit: pageSize,
				cityid: 440300,
				longitude: 114.03179,
				latitude: 22.5299
			};	
			var cityId = 0;
			var lat = '';
			var lon = '';						
			$(window).on('scroll', function(ev){				
				var o = document.querySelector('.goods_lists');
				if (o.getBoundingClientRect().top <= 0) {
					$('.classify').addClass('class2');
					$('.save_money').css('paddingTop', '3rem');					
				} else {
					$('.classify').removeClass('class2');
					$('.save_money').css('paddingTop', '0');					
				}
			});				
			getDegree();
			function getDegree() { //获取经纬度
				Promise.all([getLocation(true), setJSAPI()]).then(function (value) {					
					var v1 = value[0];	
					lat = v1.latitude;
					lon = v1.longitude;	
					$('.share2').on('click', function(){								
						go('/wechat/pages/dianshang.html?longitude='+ lat +'&latitude='+ lon );
					});		
				});
			}
			function datas() {
				ajaxGet('firework/goods/findbyadplace.json', obj, function(data){														
					if (data.code === 200) {	
						dataArr = data.data;																													
						$(_this).find('.goods_lists').append(template('tpl_member_data', data));
						if (dataArr.length < pageSize) {							
							$('.show_more').html('无更多数据');							
						}else {
							$('.show_more').html('查看更多');						
						}						
					}					
				});
			}
			//分类
			ajaxGet('firework/adplace/findbysiteid.json', {id: 110}, function(data1){
				if (data1.code === 200) {
					classArr = data1.data;
					obj.id = classArr[index].id;
					for (var i=0;i<classArr.length;i++) {
						str += '<p>'+ classArr[i].title +'</p>';																	
					}					
					str += '<p></p>';
					$(_this).find('.classify').append(str);	
					$('.classify').find('p').eq(0).addClass('sel');
					datas();									
				}				
			});															
			$('.classify').delegate('p', 'click', function(ev){		
				$(_this).find('.goods_lists').html('');	
				dataArr = [];																
				index = $(this).index();
				$(this).addClass('sel').siblings().removeClass('sel');
				obj.id = classArr[index].id;				
				page = 1;
				obj.page = 1;
				datas();
				//滚动居中
				var item = $(".sel");
				var container = $(".classify");
				var itemOffset = item.offset();
				var itemOffsetLeft = itemOffset.left + container.scrollLeft();
				var centerLeft = ( container.width() - item.width()) / 2;
				container.animate({
					scrollLeft: itemOffsetLeft - centerLeft
				}, 600);				
			});			
			$('.show_more').on('click', function(){					
				go('#/vip_goods');			
			});
			$('.goods_lists').delegate('.goods_list', 'click', function(ev){				
				var objj = {};
				objj.id = $(this).attr('id');				
				objj.shopid = $(this).attr('shopid');
				objj.latitude = $(this).attr('latitude');
				objj.longitude = $(this).attr('longitude');									
				go('#/goods_details/'+ $(this).attr('id'));						
			});
		}
	};
	router.push(save_money);

	var connect_store = {
		url: "/connect_store",
		className: "connect_store",
		render: function() {
			return setTitle("How to Connect Store"), template("tpl_connect_store", {});
		},
		bind: function() {
			var _this=this;
			var page2 = 1;
			var pageSize2 = 8;
			var arr_2 = [];
			//自己关联的宝店
			function invite() {
				ajaxGet('firework/invite-bonus.json', {page: page2,limit: pageSize2,mine: 1}, function(data){					
					if (data.code === 200) {
						arr_2 = data.data;						
						if (arr_2.length < pageSize2) {
							$('.more2').html('无更多数据');
							$('.more2').off();
						}
						$(_this).find('.lists').append(template('tpl_invite_data', data));
					}
				}, function(err){
					$('.more2').html('暂无数据');
					$('.more2').off();
				});
			}		
			invite();
			$('.more2').on('click', function(){				
				page2++;
				invite();
				if (arr_2.length < pageSize2) {
					$('.more2').html('无更多数据');
					$(this).off();
				}
			});
			
		}
	};
	router.push(connect_store);

	var vip = {
		url: "/vip",
		className: "vip",
		render: function() {
			return setTitle("宝店客VIP"), template("tpl_vip", {});
		},
		bind: function() {
			var _this=this;
			
		}
	};
	router.push(vip);

	var vip_goods = {
		url: "/vip_goods",
		className: "vip_goods",
		render: function() {
			return setTitle("宝店客VIP商品"), template("tpl_vip_goods", {});
		},
		bind: function() {
			var _this=this;
			var index = 0;						
			var classArr = [];	
			var dataArr = [];		
			var str = '';		
			var obj = {
				id: index,				
				cityid: 440300,
				longitude: 114.03179,
				latitude: 22.5299
			};						
			function datas() {		
				$('.dropload-down').remove();
				pullLoadData(_this, '.goods_lists2', '.goods_lists', 'firework/goods/findbyadplace.json', 'tpl_member_data', obj, function(data){
												
				}, 'tpl_no_member');							
			}			
			//分类
			ajaxGet('firework/adplace/findbysiteid.json', {id: 110}, function(data1){
				if (data1.code === 200) {
					classArr = data1.data;
					obj.id = classArr[index].id;
					for (var i=0;i<classArr.length;i++) {
						str += '<p>'+ classArr[i].title +'</p>';																	
					}					
					str += '<p></p>';
					$(_this).find('.classify').append(str);	
					$('.classify').find('p').eq(0).addClass('sel');
					datas();									
				}				
			});															
			$('.classify').delegate('p', 'click', function(ev){					
				$(_this).find('.goods_lists').html('');	
				dataArr = [];																
				index = $(this).index();
				$(this).addClass('sel').siblings().removeClass('sel');
				obj.id = classArr[index].id;												
				datas();					
				//滚动居中
				var item = $(".sel");
				var container = $(".classify");
				var itemOffset = item.offset();
				var itemOffsetLeft = itemOffset.left + container.scrollLeft();
				var centerLeft = ( container.width() - item.width()) / 2;
				container.animate({
					scrollLeft: itemOffsetLeft - centerLeft
				}, 600);			
			});			
			$('.goods_lists').delegate('.goods_list', 'click', function(ev){				
				var objj = {};
				objj.id = $(this).attr('id');				
				objj.shopid = $(this).attr('shopid');
				objj.latitude = $(this).attr('latitude');
				objj.longitude = $(this).attr('longitude');									
				go('#/goods_details/'+ $(this).attr('id'));																
			});

		}
	};
	router.push(vip_goods);	

	var gids = 0;
	var goods_details = {
		url: "/goods_details/:id",
		className: "goods_details",
		render: function() {
			gids = this.params.id;			
			return setTitle("商品详情"), template("tpl_goods_details", {});
		},
		bind: function() {
			$('body,html').scrollTop(0);
			var _this=this;	
			var index = 0;
			var imgArr = [];			
			var str = '';
			var obje = {};				
			obje.id = gids;			
			obje.with_introduction = 1; //是否查询商品简介												
			ajaxGet('mall/goods/info.json', obje, function(data){
				if (data.code === 200) {					
					$('.swiper-wrapper').append(template('tpl_goods_detail_img', data.data.images));	
					new Swiper("#swiper-container-goods", { 
						initialSlide: 0,
						speed: 400,                                   
						autoplay: {
							delay: 5000,
						}, 
						pagination: {
							el: '.swiper-pagination',
							clickable: true,
						},
						preventLinksPropagation : true,
						loop : false,
						on: {
							slideChangeTransitionStart: function() {						
								index = this.activeIndex;				                    
							},
							slideChangeTransitionEnd: function(){
								this.autoplay.start();
							},              
						}
					});
					//is_show=1正常 其它为已下架
					if (data.data.is_show !== 1) { //已下架
						$('.hides').show();
						return;
					}
					$('.shows').show();
					//显示开奖补贴					
					if (data.data.shopinfo.bonus&&data.data.shopinfo.bonus.id) {												
						var open = data.data.shopinfo.bonus;						
						$('.open_prize_maxs').show();
						$('.allowances').show();
						$('.max_bu').html(twoDecimal(open.maxButieMoney));
						$('.remain').html(open.userCount);
						$('.act_time').html(open.timeStr);
					}					
					$('.info_top').find('h5').html(data.data.title);
					$('.price1').html(twoDecimal(data.data.price));
					$('.quick').html(data.data.shippingMoney);
					$('.saled').html(data.data.sale_count);	
					//店铺是否认领
					if (data.data.shopinfo.is_claim) { //认领
						if (data.data.isShopVip && data.data.isvip) {
							$('.bottom2').css('visibility','visible');
						}else {
							$('.bottom1').css('visibility','visible');
						}						
					}else {	//未认领
						$('.bottom3').css('visibility','visible');
					}	
					$('.member_descs').show();
					$('.member_price').show();
					$('.price2').html(twoDecimal(data.data.price*data.data.viprate/100));
					$('.discount').html(twoDecimal(data.data.price*(1-data.data.viprate/100)));
					$('.price3').html(twoDecimal(data.data.price*data.data.viprate/100));								
										
					$('.introduction').html(data.data.introduction);							
					//购买
					$('.buy,.shopcart').on('click',function(){
						$('.mask').show();
					});
					//取消
					$('.cancels').on('click',function(){
						$('.mask').hide();
					});
					//去app
					$('.goes,.btn1,.btn3').on('click',function(){
						go('http://a.app.qq.com/o/simple.jsp?pkgname=com.mofing');
					});
					//成为会员
					$('.be_member,.bottom3').on('click', function(){
						$('.full_mask').show();	
						$('.member_msg_4').slideDown(150);
						setTimeout(function(){	
							ajaxPost('service/vips/apply.json', {id:data.data.shop_id, gid:data.data.id}, function(data2){								
								$('.member_msg_4').hide();
								if (data2.result === 3 || data2.result === 5) {
									$('.member_msg_1').show();;
								}else if (data2.result === 6) {
									$('.member_msg_3').show();;
								}																			
							}, function(err){								
								$('.member_msg_4').hide();
								if (err.result === 1 || err.result === 2) { //失败
									$('.member_msg_5').show();
									$('.msg_text').html(err.message);
								}else if (err.result === 4) { //宝友数量不足									
									$('.member_msg_2').show();
								}							
							});
						}, 3000);																								
					});
					//关闭
					$('.close_member').on('click', function(){
						$('.full_mask').hide();						
						$('.member_msg').slideUp(150);
					});
					//喊宝友帮忙
					$('.btn2').on('click', function(){

					});					
				}				
			});	
			function twoDecimal(val) {				
				return val.toFixed(2);
			}			
		}
	};
	router.push(goods_details);

	var vip_store = {
		url: "/vip_store",
		className: "vip_store",
		render: function() {
			return setTitle("宝店客VIP宝店"), template("tpl_vip_store", {});
		},
		bind: function() {
			var _this=this;
			var cityId = 0;
			var page3 = 1;
			var pageSize3 = 4;
			var obj3 = {				
				reward: 1
			};
			ajaxGet('utils/ip/city.json', {}, function(data3){				
				if (data3.code === 200) {
					cityId = data3.data.city_id;
					pullLoadData(_this, '.vip_lists', '.vip_list2', 'mall/stores/findbycidsqid/'+ cityId +'.json', 'tpl_vip_data', obj3, function(data){
																			
					}, 'tpl_no_member');																				
				}
			});					
		}
	};
	router.push(vip_store);

	__inline('citys.js');
	__inline('diamonds.js');
	router.push(home).setDefault("/").init();
});


window.chartColors = {
	red: 'rgb(255, 99, 132)',
	orange: 'rgb(255, 159, 64)',
	yellow: 'rgb(255, 205, 86)',
	green: 'rgb(75, 192, 192)',
	blue: 'rgb(54, 162, 235)',
	purple: 'rgb(153, 102, 255)',
	grey: 'rgb(201, 203, 207)',
	white:'rgb(255,255,255)'
};
var chartOptions={
	responsive: true,
	legend: {
		display:false,
	},
	tooltips: {
		displayColors:false,
		bodyFontColor:'#000',
		backgroundColor:'rgba(205, 193, 229, 0.91)',
        callbacks: {
        	title:function(tooltipItem){
        		return '';
        	},
            label: function(tooltipItem, data) {
                return (Math.round(tooltipItem.yLabel * 100) / 100)+"元";
            }
        }
 }
}
$(function(){
	//默认分享
	setJSAPI(10386).then(function(){
		console.log("默认分享初始化完成")
	})
})
function initHeadFun(_this){
	ajaxGet("firework/bdk/counts.json",{type:2},function(data){
		$(_this).find("#number").html(data.data);
	});
	//输入宝店客id
	$(_this).find("#btn_check").click(function(){
		var id = parseInt($(_this).find("#inputNumber").val());
		if(!id || id<1){
			showErrorMsg("钻石宝店客号码不正确");
			return false;
		}
		//判断号码是否为宝店客
		ajaxGet("firework/bdk/isdiamond.json",{id:id},function(data){
			//显示钻石宝店客信息
			go("#/diamondinfo/"+id);
		},function(){
			//用户不存在
			showErrorMsg("钻石宝店客号码不存在");
		});
	});
}
